﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mind.SampleProject.Data;
using Mind.Data;
using System.IO;
using System.Diagnostics;
//using CaixaDigital.DAL;
//using CaixaDigital.DAL;

namespace Mind.SampleProject
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();

            //using (DataAccessTransaction tran = DataAccessManager.Current.CreateTransaction(IsolationLevel.ReadCommitted))
            //{
            //    try
            //    {
            //        foreach (Seller s in Seller.FindTop(10))
            //        {
            //            Console.WriteLine(s.Name);

            //            s.Name = String.Format("{0}.", s.Name);
            //            s.Save();
            //        }
            //        tran.Commit();
            //    }
            //    catch
            //    {
            //        tran.Rollback();
            //        throw;
            //    }
            //}




            //Seller uou = new Seller();
            //uou.Name = "teste";
            //uou.Save();

            //foreach (Seller s in Seller.FindBySample(new Seller()))
            //    WrapperCache.Set(s);

            //foreach (Seller s in WrapperCache.FindAllCached<Seller>())
            //    Console.WriteLine(s.Name);

            //foreach (Product p in Product.FindAll())
            //{
            //    Console.WriteLine(p.ToString());
            //}
            
            






        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            //FolderBrowserDialog folderDialog = new FolderBrowserDialog();
            //if (folderDialog.ShowDialog() != DialogResult.OK)
            //    return;

            string dir = @"..\..\..\Mind.SampleProject\teste";

            //string connectionString = @"Data Source=..\..\..\SampleMindProject.sqlite;";
            string connectionString = @"server=localhost;User Id=root;password=root;Persist Security Info=True;database=capital";
            DataAccess con = DataAccessManager.CreateDataAccess("generate", DataAccessProvider.MySQL, connectionString);
            DataAccessManager.Current = con;

            string temp = Path.GetTempFileName();

            //File.WriteAllText(temp, DataSourceSchema.SchemaDiscover(con.ConnectionName));
            //Process p = new Process();
            //p.StartInfo.FileName = @"C:\Program Files\Mozilla Firefox\firefox.exe";
            //p.StartInfo.Arguments = temp;
            //p.Start();

            //return;

            Mind.Data.DataSourceSchema g = new Mind.Data.DataSourceSchema(con.ConnectionName);
            g.GenerateFiles(dir, "Capital.Data");
            



            //StringBuilder sb = new StringBuilder();

            //Imogen.Data.UnidadeFederativa uf = 
            //    Imogen.Data.UnidadeFederativa.FindById(1) ??
            //    new Imogen.Data.UnidadeFederativa();
            
            //uf.UnidadeFederativaId = 1;
            //uf.Nome = "RS";
            //uf.Sigla = "RS";
            //uf.Save();


            //foreach (Imogen.Data.UnidadeFederativa item in Imogen.Data.Usuario.))
            //{
            //    MessageBox.Show(item.Nome);
            //}

            //using (IEnumerator<CaixaDigital.DAL.Posto> postoReader = CaixaDigital.DAL.Posto.FindTop(10).GetEnumerator())
            //{
            //    while (postoReader.MoveNext())
            //    {
            //        sb.AppendFormat("{0}: {1}", postoReader.Current.PostoID, postoReader.Current.Nome);
            //        sb.AppendLine();
            //    }
            //}
            //MessageBox.Show(sb.ToString());
            //using (IEnumerator<Posto> reader = new DataReaderIterator<Posto>(DataAccessManager.Current.ExecuteReader(
            //    @"SELECT distinct p.* from Posto p left outer join Funcionario f on f.PostoId = p.PostoId where f.Ativo = 1")).GetEnumerator())
            //{
            //    while (reader.MoveNext())
            //    {
            //        sb.AppendFormat("{0}: {1}", reader.Current.PostoID, reader.Current.Nome);
            //        sb.AppendLine();
            //    }
            //}
            //MessageBox.Show(sb.ToString());
        }
            
        
    }
}
